home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr11 / powerb5.zip / P5DOS009.TIP < prev    next >
Text File  |  1993-06-01  |  2KB  |  37 lines

  1. I've discovered a way to manipulate text strings in batch
  2. files, thanks to a little-known aspect of the DOS FOR
  3. command: If a string in the parenthesized portion of FOR's
  4. parameters is preceded by a slash, DOS splits it into two
  5. strings: the first character, and the remainder of the
  6. string. To see this trick in action, enter the command FOR
  7. %Y IN (/1234) DO ECHO %Y at the DOS prompt. DOS first echoes
  8. '1', then '234'. Enclosed are two batch files that show how
  9. you can use this hidden talent. The first, LENGTH.BAT,
  10. returns as the environment variable LNGTH the length of a
  11. word stored in another variable called STRING. The second,
  12. OFFLEFT.BAT, deletes the first N characters of STRING, where
  13. N and STRING are both environment variables. Use SET to
  14. create STRING and N before running these batch files and to
  15. see the results.
  16.  
  17. David Graczyk
  18. Amherst, New York
  19.  
  20. Editor's Note: Before I saw this tip, I didn't know that
  21. DOS's batch language had even rudimentary string-handling
  22. capabilities, but this technique opens the door to all sorts
  23. of ingenious tricks. For example, you could create a menu
  24. that allows you to select several options, each represented
  25. by a letter or digit, at one time by typing them in sequence
  26. on the command line. The two sample batch files LENGTH.BAT
  27. and OFFLEFT.BAT are both in the P5DOS directory of your
  28. PowerBase *.* Volume 5 diskette.
  29.  
  30.  
  31. Title: Fantastic FOR
  32. Category: DOS
  33. Issue Date: September, 1992
  34. Editor: Brett Glass
  35. Supplementary Files: P5DOS\LENGTH.BAT, P5DOS\OFFLEFT.BAT
  36. Filename: P5DOS009.TIP
  37.